package com.rc.evcharger.service.hlht;

import com.rc.evcharger.mapper.hlht.HlhtOperatorTenantMapper;
import com.rc.evcharger.model.hlht.HlhtOperatorTenant;
import com.rc.evcharger.model.hlht.HlhtOperatorTenantExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * Created by sven on 2021/01/09
 */
@Service
public class HlhtOperatorTenantServiceImpl implements HlhtOperatorTenantService {
    @Autowired
    private HlhtOperatorTenantMapper hlhtOperatorTenantMapper;

    @Override
    public HlhtOperatorTenantMapper getMapper() {
        return hlhtOperatorTenantMapper;
    }

    @Override
    public HlhtOperatorTenant selectHlhtOperatorByToken(String token) {
        HlhtOperatorTenantExample example = new HlhtOperatorTenantExample();
        example.createCriteria().andTokenEqualTo(token).andStatusEqualTo("0");
        List<HlhtOperatorTenant> list = hlhtOperatorTenantMapper.selectByExample(example);
        if (!CollectionUtils.isEmpty(list)) {
            return list.get(0);
        }
        return null;
    }

    //@Override
    //public HlhtOperatorTenant selectHlhtOuterByTenantCode(String tenantCode) {
    //    HlhtOperatorTenantExample example = new HlhtOperatorTenantExample();
    //    example.createCriteria().andTenantCodeEqualTo(tenantCode).andStatusEqualTo("0");
    //    List<HlhtOperatorTenant> list = hlhtOperatorTenantMapper.selectByExample(example);
    //    if (!CollectionUtils.isEmpty(list)) {
    //        return list.get(0);
    //    }
    //    return null;
    //}

    @Override
    public HlhtOperatorTenant selectHlhtOperatorByOperatorId(String tenantCode, String operatorId) {
        HlhtOperatorTenantExample example = new HlhtOperatorTenantExample();
        example.createCriteria().andTenantCodeEqualTo(tenantCode).andHlhtOperatorIdEqualTo(operatorId).andStatusEqualTo("0");
        List<HlhtOperatorTenant> list = hlhtOperatorTenantMapper.selectByExample(example);
        if (!CollectionUtils.isEmpty(list)) {
            return list.get(0);
        }
        return null;
    }
}
